<?php
/**
 * Created by PhpStorm.
 * User: wodrow
 * Date: 2018/10/12
 * Time: 9:32
 */
/**
 * @var \yii\web\View $this
 * @var \common\models\db\Docu $model
 * @var \home\modules\docu\models\FormComment $form_comment
 * @var \yii\data\ActiveDataProvider $commentDataProvider
 * @var \home\modules\docu\models\FormCommentReply $form_reply
 * @var \common\models\db\DocuCommentReply $reply_query
 */

use common\components\tools\Html;
use kartik\form\ActiveForm;
use yii\widgets\ListView;
use common\rewrite\widgets\LinkPager;
use yii\captcha\Captcha;
use yii\data\ActiveDataProvider;
?>

<!-- Comments Form -->
<div class="well">
    <h4>评论:</h4>
    <?php if (Yii::$app->user->isGuest): ?>
        <?= \home\models\FormLogin::getLoginBoxA("请登陆后评论") ?>
    <?php else: ?>
        <?php $form_comm = ActiveForm::begin(['options' => [
            'data-pjax' => true,
        ]]); ?>
        <?= $form_comm->field($form_comment, 'docu_id')->hiddenInput(['value' => $model->id])->label(false) ?>
        <?= $form_comm->field($form_comment, 'body')->widget(\kriss\wangEditor\WangEditorWidget::class)->label(false) ?>
        <?= $form_comm->field($form_comment, 'code', [])->widget(Captcha::class)->label(false) ?>
        <?= Html::submitButton('评论', ['class' => "btn btn-primary"]) ?>
        <?php ActiveForm::end(); ?>
    <?php endif; ?>
</div>

<hr>

<!-- Posted Comments -->

<?= ListView::widget([
    'dataProvider' => $commentDataProvider,
    'itemView' => function($model) use ($form_reply, $reply_query){
        $reply_query = $reply_query->where(['docu_comment_id' => $model->id]);
        $replyDataProvider = new ActiveDataProvider([
            'query' => $reply_query,
            'pagination'=>[
                'pageSize' => 5,
                'pageSizeParam' => "reply_per_page_".$model->id,
                'pageParam' => 'reply_p_'.$model->id,
            ],
        ]);
        return $this->render('/public/_comment_list', ['model' => $model, 'form_reply' => $form_reply, 'replyDataProvider' => $replyDataProvider]);
    },
    'layout' => '{items}{summary}{pager}',
    'itemOptions' => ['class' => "comment_list_box"],
    'pager' => [
        'class' => LinkPager::class,
        'go' => true,
    ],
]) ?>
